package com.weaver.drools.business.execution.controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.weaver.drools.business.execution.service.IQCmnOperatepoint20Service;
import com.weaver.drools.business.execution.service.IQSelfEnemploycontact72Service;
import com.weaver.drools.business.execution.service.IViewInsVcInpectionpandectService;
import com.weaver.drools.common.controller.CommonController;
import com.weaver.drools.common.entity.ASfAccidentdetails1039;
import com.weaver.drools.common.entity.ASfDetailsandemployee1048;
import com.weaver.drools.common.entity.ActCondition;
import com.weaver.drools.common.entity.DBptype113;
import com.weaver.drools.common.entity.DCaseoringintype430;
import com.weaver.drools.common.entity.DCauseofactiontype449;
import com.weaver.drools.common.entity.DDatastatus4;
import com.weaver.drools.common.entity.DDatatype3;
import com.weaver.drools.common.entity.DDetailsregistertype123;
import com.weaver.drools.common.entity.DSex35;
import com.weaver.drools.common.entity.DSuperviseviewtype83;
import com.weaver.drools.common.entity.DWrit100;
import com.weaver.drools.common.entity.EAqInquiryundertaker335;
import com.weaver.drools.common.entity.EAqInsInpection124;
import com.weaver.drools.common.entity.EAqInsInpectionpandect599;
import com.weaver.drools.common.entity.EAqInsInquiryrecord162;
import com.weaver.drools.common.entity.EAqInsReview125;
import com.weaver.drools.common.entity.EAqInsReviewrectify128;
import com.weaver.drools.common.entity.EAqInsReviewtmeasure423;
import com.weaver.drools.common.entity.EAqInsSupervisor129;
import com.weaver.drools.common.entity.EAqInsTreatmentmeasure422;
import com.weaver.drools.common.entity.EAqInsUndertaker272;
import com.weaver.drools.common.entity.EAqPnlOverview146;
import com.weaver.drools.common.entity.EAqPnlOverviewbprecord561;
import com.weaver.drools.common.entity.EAqPnlPor163;
import com.weaver.drools.common.entity.QCmnDepartment23;
import com.weaver.drools.common.entity.QCmnOperatepoint20;
import com.weaver.drools.common.entity.QSelfEnemploycontact72;
import com.weaver.drools.common.entity.UUsrUser36;
import com.weaver.drools.common.entity.EAqInsInsrectify127;
import com.weaver.drools.common.entity.ViewInsVcInpectionpandect;
import com.weaver.drools.common.utils.BpTypeUtools;
import com.weaver.drools.common.utils.DateUtliToos;
import com.weaver.drools.common.utils.ReturnMessage;
import com.weaver.drools.business.execution.service.IASfAccidentdetails1039Service;
import com.weaver.drools.business.execution.service.IASfDetailsandemployee1048Service;
import com.weaver.drools.business.execution.service.IDCaseoringintype430Service;
import com.weaver.drools.business.execution.service.IDCauseofactiontype449Service;
import com.weaver.drools.business.execution.service.IDWrit100Service;
import com.weaver.drools.business.execution.service.IEAqInquiryundertaker335Service;
import com.weaver.drools.business.execution.service.IEAqInsInpectionpandect599Service;
import com.weaver.drools.business.execution.service.IEAqInsInsrectify127Service;
import com.weaver.drools.business.execution.service.IEAqInsReview125Service;
import com.weaver.drools.business.execution.service.IEAqInsReviewrectify128Service;
import com.weaver.drools.business.execution.service.IEAqInsSupervisor129Service;
import com.weaver.drools.business.execution.service.IEAqInsTreatmentmeasure422Service;
import com.weaver.drools.business.execution.service.IEAqPnlOverview146Service;
import com.weaver.drools.business.execution.service.IEAqPnlPor163Service;
import com.weaver.drools.business.drools.service.IActRuleService;
@Controller
public class PnlporController extends CommonController{

	/**立案记录表数据类型编号**/
	private static final Long DATATYPE_163=57L;
	/**立案审批操作日志表数据类型编号**/
	private static final Long DATATYPE_164=57L;
	/**立案审批操作日志细节表*/
	private static final Long DATATYPE_165=57L;
	/**行政处罚总览记录表数据类型编号**/
	private static final Long DATATYPE_146=57L;
	/**承办人记录表类型编号**/
	private static final Long DATATYPE_272=57L;
	/**立案审批操作日志修改操作日志类型编号**/
	private static final Long BUSINESS_LOG_TYPEID_U_164=1L;
	/**立案审批操作日志审核操作日志类型编号**/
	private static final Long BUSINESS_LOG_TYPEID_V_164=2L;
	/**立案审批操作日志审批操作日志类型编号**/
	private static final Long BUSINESS_LOG_TYPEID_P_164=3L;
	/**流程环节编号**/
	private static final Long BPTYPEID=11L;
	
	@Autowired
	private IQCmnOperatepoint20Service cmnOperatepoint20Service;
	@Autowired
	private IEAqInsInpectionpandect599Service insInpectionpandect599Service;
	@Autowired
	private IEAqInquiryundertaker335Service inquiryundertaker335Service;
	@Autowired
	private IEAqInsSupervisor129Service insSupervisor129Service;
	@Autowired
	private IViewInsVcInpectionpandectService viewInsVcInpectionpandectService;
	@Autowired
	private IEAqInsReview125Service insReview125Service;
	@Autowired
	private IEAqInsReviewrectify128Service insReviewrectify128Service;
	@Autowired
	private IEAqInsInsrectify127Service insInsrectify127Service;
	@Autowired
	private IEAqInsTreatmentmeasure422Service treatmentmeasure422Service;
	@Autowired
	private IASfDetailsandemployee1048Service sfDetailsandemployee1048Service;
	@Autowired
	private IASfAccidentdetails1039Service iASfAccidentdetails1039Service;
	@Autowired
	private IQSelfEnemploycontact72Service enemploycontact72Service;
	@Autowired
	private IDWrit100Service writ100Service;
	@Autowired
	private IDCauseofactiontype449Service causeofactiontype449Service;
	@Autowired
	private IDCaseoringintype430Service caseoringintype430Service;
	@Autowired
	private IEAqPnlPor163Service pnlPor163Service;
	@Autowired
	private IEAqPnlOverview146Service overview146Service;
	//规则保存
	@Autowired
	private IActRuleService actRuleService;
	
	/**
	 * 新增立案审批表信息界面转发
	 * @return
	 */
	@RequestMapping(value ="pnlPorAddForword",method = RequestMethod.GET)
	public String pnlPorAddForword(){
		String porType=this.getRequest().getParameter("porType");
		String accidentDetailsId=this.getRequest().getParameter("accidentDetailsId");
		String inpectionPandectId=this.getRequest().getParameter("inpectionPandectId");
		String operatePointId=this.getRequest().getParameter("operatePointId");
		//经营点名称
		String operatePointName="";
		//单位地址
		String registerAddress="";
		//法人代表
		String legalPerson="";
		//法人代表电话
		String legalPersonPhone="";
		//法人代表职务
		String duties="";
		//邮编
		String postCode="";
		try {
			if(inpectionPandectId!=null && !inpectionPandectId.equals("")){
				EAqInsInpectionpandect599 inpectionPandectBean=insInpectionpandect599Service.findById(Long.valueOf(inpectionPandectId));
				EAqInsInpection124 inpectionBean=inpectionPandectBean.getEAqInsInpection124();
				if(inpectionBean.getQCmnOperatepoint20()!=null){
					operatePointId=inpectionBean.getQCmnOperatepoint20().getOperatepointid().toString();
					legalPerson=inpectionBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalperson();
					legalPersonPhone=inpectionBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalpersonphone();
				}
				operatePointName=inpectionBean.getInsunit();
				registerAddress=inpectionBean.getAddress();
				postCode=inpectionBean.getZipcode();
				duties=inpectionBean.getDuties();
				//得到承办人信息
				String underTaker="";
				String underTakerId="";
				Set<EAqInsInquiryrecord162> inquiryRecordList=inpectionPandectBean.getEAqInsInquiryrecord162s();
				if(inquiryRecordList.size()!=0){
					EAqInsInquiryrecord162 inquiryRecordBean=inquiryRecordList.iterator().next();
					underTaker=inquiryRecordBean.getParty();
					List<EAqInquiryundertaker335> undertakerList=inquiryundertaker335Service.findList(inquiryRecordBean.getPnlinquiryrecordid().toString(),null);
					for (int i = 0; i < undertakerList.size(); i++) {
						underTakerId+=undertakerList.get(i).getQSelfEnemploycontact72().getContactid()+"#";
					}
				}else{
					underTaker=inpectionBean.getParty();
					List<EAqInsSupervisor129> supervisorList=insSupervisor129Service.findList(null,null,inpectionBean.getInpectionid().toString(),null);
					for (int i = 0; i < supervisorList.size(); i++) {
						underTakerId+=supervisorList.get(i).getQSelfEnemploycontact72().getContactid()+"#";
					}
				}
				this.getRequest().setAttribute("inpectionPandectId",inpectionPandectId);
				this.getRequest().setAttribute("underTaker", underTaker);
				this.getRequest().setAttribute("underTakerId", underTakerId);
				//得到监督检查过程中使用的文书
				List<ViewInsVcInpectionpandect> viewInsVcInpectionPandectList=viewInsVcInpectionpandectService.findList(Long.valueOf(inpectionPandectId));
				this.getRequest().setAttribute("viewInsVcInpectionPandectList",viewInsVcInpectionPandectList);
				//行为规范
				String rectifyBasis="";
				//判断是否曾经经过复查
				List<EAqInsReview125> reviewBeanList=insReview125Service.findListByInpectionPandectId(Long.valueOf(inpectionPandectId));
				if(reviewBeanList!=null && reviewBeanList.size()>1){
					//判断当前最后一次复查后是否进行过整改，如果进行过整改，则取最后一个复查记录的整改记录，
					EAqInsReviewrectify128 aqInsReviewrectify128 =insReviewrectify128Service.findLastBeanByInpectionPandectId(inpectionPandectId);
					if(aqInsReviewrectify128!=null && aqInsReviewrectify128.getReviewrectifyid()!=null){
						rectifyBasis=aqInsReviewrectify128.getDeregulation();
					}else{
						EAqInsReview125 lastReviewBean=reviewBeanList.get(1);
						Set<EAqInsReviewtmeasure423> insReviewtmeasure423 = lastReviewBean.getEAqInsReviewtmeasure423s();
						for (EAqInsReviewtmeasure423 aqInsReviewtmeasure423 : insReviewtmeasure423) {
							if(aqInsReviewtmeasure423.getIsdeleted().toString().equals("0")){
								rectifyBasis=aqInsReviewtmeasure423.getDeregulation();
							}
						}
					}
				}else{
					EAqInsInsrectify127 aqInsInsrectify127 =insInsrectify127Service.findLastBeanByInpectionPandectId(inpectionPandectId);
					if(aqInsInsrectify127!=null && aqInsInsrectify127.getInsrectifyid()!=null){
						rectifyBasis=aqInsInsrectify127.getDeregulation();
					}else{
						EAqInsTreatmentmeasure422 treatmentMeasureBean= treatmentmeasure422Service.findNotCurrentBeanByInpectionPandectId(Long.valueOf(inpectionPandectId));
						rectifyBasis=treatmentMeasureBean.getDeregulation();
					}
				}
				this.getRequest().setAttribute("rectifyBasis",rectifyBasis);
			}else if(operatePointId!=null && !operatePointId.equals("")){
				QCmnOperatepoint20 operatePoint=cmnOperatepoint20Service.findById(Long.valueOf(operatePointId));
				operatePointName=operatePoint.getOperatepointname();
				legalPerson=operatePoint.getQCmnUnit18().getLegalperson();
				legalPersonPhone=operatePoint.getQCmnUnit18().getLegalpersonphone();
				registerAddress=operatePoint.getOperatepointaddress();
				postCode=operatePoint.getPostcode();
			}else if(accidentDetailsId!=null && !accidentDetailsId.equals("")){
				ASfAccidentdetails1039 accidentDetailsBean=iASfAccidentdetails1039Service.findById(Long.valueOf(accidentDetailsId));
				operatePointName=accidentDetailsBean.getAccidentoptname();
				registerAddress=accidentDetailsBean.getAccidentoptaddress();
				if(accidentDetailsBean.getQCmnOperatepoint20()!=null){
					operatePointId=accidentDetailsBean.getQCmnOperatepoint20().getOperatepointid().toString();
					legalPerson=accidentDetailsBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalperson();
					legalPersonPhone=accidentDetailsBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalpersonphone();
					postCode=accidentDetailsBean.getQCmnOperatepoint20().getPostcode();
				}
				
				if(accidentDetailsBean.getQCmnOperatepoint20()!= null){
					operatePointId=accidentDetailsBean.getQCmnOperatepoint20().getOperatepointid().toString();
					legalPerson=accidentDetailsBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalperson();
					legalPersonPhone=accidentDetailsBean.getQCmnOperatepoint20().getQCmnUnit18().getLegalpersonphone();
				}
				//得到承办人信息
				String underTaker=accidentDetailsBean.getAccidentsurveyors();
				String underTakerId="";
				List<ASfDetailsandemployee1048> employeeList=sfDetailsandemployee1048Service.findEmployeeListByAccidentDetailsId(Long.valueOf(accidentDetailsId),"0");
				for (int i = 0; i < employeeList.size(); i++) {
					QSelfEnemploycontact72 enemploycontact72=enemploycontact72Service.findEntityByEmployeeId(employeeList.get(i).getQSelfEmployee69().getEmployeeid());
					if(enemploycontact72!=null){
						underTakerId+=enemploycontact72.getContactid()+"#";
					}
				}
				this.getRequest().setAttribute("accidentDetailsId",accidentDetailsId);
				this.getRequest().setAttribute("underTaker", underTaker);
				this.getRequest().setAttribute("underTakerId", underTakerId);
				this.getRequest().setAttribute("accidentDetailsId",accidentDetailsId);
			}
			//得到文书信息
			String currentYear=DateUtliToos.getFormatDate(Calendar.getInstance(),true).substring(0,4);
			Long unitId=154L;
			DWrit100 writBean=writ100Service.findLastWritBean(8L,unitId,currentYear,0L);
			this.getRequest().setAttribute("writBean",writBean);
			//案件來源
			List<DCauseofactiontype449> causeOfActionTypeList=causeofactiontype449Service.findAll();
			this.getRequest().setAttribute("causeOfActionTypeList",causeOfActionTypeList);
			List<DCaseoringintype430> caseOringinTypeList=caseoringintype430Service.findAll();
			this.getRequest().setAttribute("caseOringinTypeList",caseOringinTypeList);
		}catch (Exception e) {
			e.printStackTrace();
		}
		this.getRequest().setAttribute("porType",porType);
		this.getRequest().setAttribute("operatePointId",operatePointId);
		this.getRequest().setAttribute("operatePointName",operatePointName);
		this.getRequest().setAttribute("legalPerson",legalPerson);
		this.getRequest().setAttribute("legalPersonPhone",legalPersonPhone);
		this.getRequest().setAttribute("registerAddress",registerAddress);
		this.getRequest().setAttribute("duties",duties);
		this.getRequest().setAttribute("postCode",postCode);
		return "pnlpor/pnlporAdd";
	}
	/**
	 * 新增立案审批表
	 * @return
	 */
	@RequestMapping(value ="pnlPorSave",method = RequestMethod.GET)
	public void pnlPorSave(){
		String cs="";
		String porType=this.getRequest().getParameter("porType");
		//现场检查笔录
		String inpectionPandectId=this.getRequest().getParameter("inpectionPandectId");
		String accidentDetailsId=this.getRequest().getParameter("accidentDetailsId");
		try {
			/**立案审批表信息*/
			EAqPnlPor163 pnlPorBean=getInstanceForPnlPorBean();
			if(porType!=null && !porType.equals("")){
				pnlPorBean.setPortype(Long.valueOf(porType));
			}
			
			//将监督检查过程归档处理
			if(inpectionPandectId!=null && !inpectionPandectId.equals("")){
				EAqInsInpectionpandect599 inpectionPandectBean=insInpectionpandect599Service.findById(Long.valueOf(inpectionPandectId));
				//标记为已记录立案
				inpectionPandectBean.setIsrecordpor(1L);
				pnlPorBean.setEAqInsInpectionpandect599(inpectionPandectBean);
			}else if(accidentDetailsId!=null && !accidentDetailsId.equals("")){
				ASfAccidentdetails1039 sfAccidentdetails1039=iASfAccidentdetails1039Service.findById(Long.valueOf(accidentDetailsId));
				Long isRecordPor=sfAccidentdetails1039.getIsrecordpor();
				if(isRecordPor==null){
					isRecordPor=1L;
				}else{
					isRecordPor++;
				}
				sfAccidentdetails1039.setIsrecordpor(isRecordPor);
				pnlPorBean.setASfAccidentdetails1039(sfAccidentdetails1039);
			}

			boolean isSuccessUpload=true;
			if(isSuccessUpload){
				pnlPor163Service.saveEAqPnlPor163(pnlPorBean);
				cs = ReturnMessage.messageData(ReturnMessage.SUCCESS, "立案审批表信息添加成功！",null);
				Map<String,Object> mapList = new HashMap<>();
		        mapList.put("pnlPor163Service", pnlPor163Service);
		        mapList.put("actRuleService", actRuleService);
				this.BusinessRuleExecutor("overview_pandect",pnlPorBean,mapList);
			}else{
				cs = ReturnMessage.messageData(ReturnMessage.FAIL, "立案审批表信息添加失败，请重新添加！",null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			cs = ReturnMessage.messageData(ReturnMessage.FAIL, "立案审批表信息添加失败，请重新添加！",null);
		}
		this.writejsonAndSession(cs);
	}
	/**
	 * 初始化立案审批表信息实例
	 */
	private EAqPnlPor163 getInstanceForPnlPorBean() throws Exception{
		UUsrUser36 SessionUserBean = this.getSessionUserBean();
		EAqPnlPor163 pnlPorBean=new EAqPnlPor163();
		SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd");
		String pnlPorId=this.getRequest().getParameter("pnlPorId");
		if(pnlPorId!=null && !pnlPorId.equals("")){
			pnlPorBean=pnlPor163Service.findById(Long.valueOf(pnlPorId));
		}else{
			//得到主键值
			Long id=pnlPor163Service.findId();
			pnlPorBean.setPorid(id);
			//数据状态
			DDatastatus4 dataStatusBean=new DDatastatus4();
			dataStatusBean.setDatastatusid(2L);
			pnlPorBean.setDDatastatus4(dataStatusBean);
		}
		//文书ID
		String writId=this.getRequest().getParameter("writId");
		DWrit100 writBean=new DWrit100();
		writBean.setWritid(Long.valueOf(writId));
		pnlPorBean.setDWrit100(writBean);
		//文书号
		String writNumber=this.getRequest().getParameter("writNumber");
		pnlPorBean.setWritnumber(writNumber);
		//流程环节
		DBptype113 bpTypeBean=new DBptype113();
		bpTypeBean.setBptypeid(BPTYPEID);
		pnlPorBean.setDBptype113(bpTypeBean);
		//案由类型ID
		String causeOfActionTypeId=this.getRequest().getParameter("causeOfActionTypeId");
		if(causeOfActionTypeId!=null && !causeOfActionTypeId.equals("")){
			DCauseofactiontype449 causeofactiontype449=new DCauseofactiontype449();
			causeofactiontype449.setCauseofactiontypeid(Long.valueOf(causeOfActionTypeId));
			pnlPorBean.setDCauseofactiontype449(causeofactiontype449);
			if(causeOfActionTypeId.equals("99")){
				//案由
				String causeOfAction=this.getRequest().getParameter("causeOfAction");
				pnlPorBean.setCauseofaction(causeOfAction);
			}else{
				pnlPorBean.setCauseofaction(null);
			}
		}
		//案件来源类型ID
		String caseOringinTypeId=this.getRequest().getParameter("caseOringinTypeId");
		if(caseOringinTypeId!=null && !caseOringinTypeId.equals("")){
			DCaseoringintype430 caseoringintype430=new DCaseoringintype430();
			caseoringintype430.setCaseoringintypeid(Long.valueOf(caseOringinTypeId));
			pnlPorBean.setDCaseoringintype430(caseoringintype430);
			if(caseOringinTypeId.equals("6") || caseOringinTypeId.equals("99")){
				//案件来源
				String caseOringin=this.getRequest().getParameter("caseOringin");
				pnlPorBean.setCaseoringin(caseOringin);
			}else{
				pnlPorBean.setCaseoringin(null);
			}
		}
		//处罚事项
		String punishmentItems=this.getRequest().getParameter("punishmentItems");
		if(punishmentItems!=null && !punishmentItems.equals("")){
			pnlPorBean.setPunishmentitems(Long.valueOf(punishmentItems));
		}else{
			pnlPorBean.setPunishmentitems(null);
		}
		//案情名称
		String caseName=this.getRequest().getParameter("caseName");
		pnlPorBean.setCasename(caseName);
		//案件接手时间
		String contactTime=this.getRequest().getParameter("contactTime");
		if(contactTime!=null && !contactTime.equals("")){
			pnlPorBean.setContacttime(format.parse(contactTime));
		}
		//承办时间
		String undertakeDate=this.getRequest().getParameter("undertakeDate");
		if(undertakeDate!=null && !undertakeDate.equals("")){
			pnlPorBean.setUndertakedate(format.parse(undertakeDate));
		}
		//案情简介
		String caseBrief=this.getRequest().getParameter("caseBrief");
		pnlPorBean.setCasebrief(caseBrief);
		//违法规定
		String deRegulation=this.getRequest().getParameter("deRegulation");
		pnlPorBean.setDeregulation(deRegulation);
		//处罚依据
		String pnlBasis=this.getRequest().getParameter("pnlBasis");
		pnlPorBean.setPnlbasis(pnlBasis);
		//拟办意见
		String deviseHandLingOpinion=this.getRequest().getParameter("deviseHandLingOpinion");
		pnlPorBean.setDevisehandlingopinion(deviseHandLingOpinion);
		//立案时间
		pnlPorBean.setPordate(null);
		//承办人
		String undertaker_text=this.getRequest().getParameter("undertaker_text");
		pnlPorBean.setUndertaker(undertaker_text);
		//记录人
		pnlPorBean.setRegistrant(undertaker_text.split(",")[0]);
		String undertaker=this.getRequest().getParameter("undertaker");
		String[] undertakers=undertaker.split("#");
		//先删除旧的
		Set<EAqInsUndertaker272> insUndertaker272s = pnlPorBean.getEAqInsUndertaker272s();
		for (EAqInsUndertaker272 aqInsUndertaker272 : insUndertaker272s) {
			aqInsUndertaker272.setIsdeleted(1L);
		}
		//在添加新的
		for (int i = 0; i < undertakers.length; i++) {
			EAqInsUndertaker272 insUndertaker272=new EAqInsUndertaker272();
			insUndertaker272.setDBptype113(bpTypeBean);
			//部门和员工关系ID
			QSelfEnemploycontact72 enemploycontact=new QSelfEnemploycontact72();
			enemploycontact.setContactid(Long.valueOf(undertakers[i]));
			insUndertaker272.setQSelfEnemploycontact72(enemploycontact);
			//立案记录ID
			insUndertaker272.setEAqPnlPor163(pnlPorBean);
			//用户ID
			UUsrUser36 user272=new UUsrUser36();
			user272.setUserid(SessionUserBean.getUserid());
			insUndertaker272.setUUsrUser36(user272);
			//数据状态ID
			DDatastatus4 dataStatus=new DDatastatus4();
			dataStatus.setDatastatusid(2L);
			insUndertaker272.setDDatastatus4(dataStatus);
			//监管角度
			DSuperviseviewtype83 superviseviewtype=new DSuperviseviewtype83();
			superviseviewtype.setSuperviseviewtypeid(4L);
			insUndertaker272.setDSuperviseviewtype83(superviseviewtype);
			//数据类型 
			DDatatype3 dataType=new DDatatype3();
			dataType.setDatatypeid(DATATYPE_272);
			insUndertaker272.setDDatatype3(dataType);
			//是否删除
			insUndertaker272.setIsdeleted(0L);
			insUndertaker272s.add(insUndertaker272);
		}
		pnlPorBean.setEAqInsUndertaker272s(insUndertaker272s);
		//报送时间
		String reportDate=this.getRequest().getParameter("reportDate");
		if(reportDate!=null && !reportDate.equals("")){
			pnlPorBean.setReportdate(format.parse(reportDate));
		}else{
			pnlPorBean.setReportdate(new Date());
		}
		pnlPorBean.setFinaldelaynum(0L);
		pnlPorBean.setIsarchived(0L);
		
		//详情登记类型
		DDetailsregistertype123 detailsregistertype=new DDetailsregistertype123();
		detailsregistertype.setDetailsregistertypeid(2L);
		pnlPorBean.setDDetailsregistertype123(detailsregistertype);
		//备注
		String remark=this.getRequest().getParameter("remark");
		pnlPorBean.setRemark(remark);
		//报送者ID
		UUsrUser36 user163=new UUsrUser36();
		user163.setUserid(SessionUserBean.getUserid());
		pnlPorBean.setUUsrUser36ByUserid(user163);
		//报送者部门ID
		QCmnDepartment23 reporteDepartment=new QCmnDepartment23();
		Long departmentId = 45L;
		reporteDepartment.setDepartmentid(departmentId);
		pnlPorBean.setQCmnDepartment23ByDepartmentid(reporteDepartment);
		//最近修改者ID
		pnlPorBean.setUUsrUser36ByLatestoperateuserid(user163);
		//监管角度
		DSuperviseviewtype83 superviseviewtype83=new DSuperviseviewtype83();
		superviseviewtype83.setSuperviseviewtypeid(4L);
		pnlPorBean.setDSuperviseviewtype83(superviseviewtype83);
		//数据类型 
		DDatatype3 dataTypeBean=new DDatatype3();
		dataTypeBean.setDatatypeid(DATATYPE_163);
		pnlPorBean.setDDatatype3(dataTypeBean);
		//是否删除
		pnlPorBean.setIsdeleted(0L);
		//处罚单位数
		Long punishUnitNum=0L;
		//处罚当事人
		String parties="";
		/**行政处罚总览表*/
		//先删除旧的
		Set<EAqPnlOverview146> pnlOverView146s = pnlPorBean.getEAqPnlOverview146s();
		for (EAqPnlOverview146 pnlOverView146 : pnlOverView146s) {
			pnlOverView146.setIsdeleted(1L);
		}
		//在添加新的
		String unitNum=this.getRequest().getParameter("unitNum");
		for(int i=1;i<=Integer.valueOf(unitNum);i++){	
			String decisionObjectType=this.getRequest().getParameter("decisionObjectType_"+i);
			if(decisionObjectType!=null && !decisionObjectType.equals("")){
				punishUnitNum++;
				EAqPnlOverview146 pnlOverView146=new EAqPnlOverview146();
				//行政处罚总览编号
				String pnlOverviewId=this.getRequest().getParameter("pnlOverviewId_"+i);
				if(pnlOverviewId!=null && !pnlOverviewId.equals("")){
					pnlOverView146=overview146Service.findById(Long.valueOf(pnlOverviewId));
				}
				//立案审批表
				pnlOverView146.setEAqPnlPor163(pnlPorBean);
				//当事人类型
				pnlOverView146.setDecisionobjecttype(Long.valueOf(decisionObjectType));
				//当事人
				String operatePointName=this.getRequest().getParameter("operatePointName_"+decisionObjectType+"_"+i);
				pnlOverView146.setOperatepointname(operatePointName);
				if(i==1){
					parties+=operatePointName;
				}else{
					parties+=","+operatePointName;
				}
				//经营点编号
				String operatePointId=this.getRequest().getParameter("operatePointId_"+decisionObjectType+"_"+i);
				if(operatePointId!=null && !operatePointId.equals("")){
					QCmnOperatepoint20 operatePoint20=new QCmnOperatepoint20();
					operatePoint20.setOperatepointid(Long.valueOf(operatePointId));
					pnlOverView146.setQCmnOperatepoint20(operatePoint20);
				}
				//当事人地址(单位地址)
				String operatePointAddress=this.getRequest().getParameter("operatePointAddress_"+decisionObjectType+"_"+i);
				pnlOverView146.setOperatepointaddress(operatePointAddress);
				//当事人类型
				if(decisionObjectType.equals("2")){
					pnlOverView146.setLegalperson(null);
					pnlOverView146.setDuties(null);
					//身份证号
					String identityCard=this.getRequest().getParameter("identityCard_"+decisionObjectType+"_"+i);
					pnlOverView146.setIdentitycard(identityCard);
					//年龄
					String age=this.getRequest().getParameter("age_"+decisionObjectType+"_"+i);
					pnlOverView146.setAge(age);					
					//性别
					String sex=this.getRequest().getParameter("sex_"+decisionObjectType+"_"+i);
					if(sex!=null && !sex.equals("")){
						DSex35 sex35=new DSex35();
						sex35.setSexid(Long.valueOf(sex));
						pnlOverView146.setDSex35(sex35);
					}
					//所在单位
					String company=this.getRequest().getParameter("company_"+decisionObjectType+"_"+i);
					pnlOverView146.setCompany(company);
					//家庭地址
					String familyAddress=this.getRequest().getParameter("familyAddress_"+decisionObjectType+"_"+i);
					pnlOverView146.setFamilyaddress(familyAddress);
				}else{
					pnlOverView146.setIdentitycard(null);
					pnlOverView146.setDSex35(null);
					pnlOverView146.setCompany(null);
					pnlOverView146.setFamilyaddress(null);
					//法定代表人
					String legalPerson=this.getRequest().getParameter("legalPerson_"+decisionObjectType+"_"+i);
					pnlOverView146.setLegalperson(legalPerson);
				}
				//职务  
				String duties=this.getRequest().getParameter("duties_"+decisionObjectType+"_"+i);
				pnlOverView146.setDuties(duties);
//				//当事人基本情况
//				pnlOverView146.setBasicsituation(basicSituation);
				//电话
				String telephone=this.getRequest().getParameter("telephone_"+decisionObjectType+"_"+i);
				pnlOverView146.setPhone(telephone);
				//邮编
				String zipCode=this.getRequest().getParameter("zipCode_"+decisionObjectType+"_"+i);
				pnlOverView146.setZipcode(zipCode);
				//是否需要调查取证
				pnlPorBean.setIsneedinvestigate(0L);
				pnlPorBean.setIsrecordinvestigate(0L);
				pnlOverView146.setIsneedinvestigate(0L);
				//子业务流程类型
				DBptype113 bPTypeBean=new DBptype113();
				bPTypeBean.setBptypeid(BPTYPEID);
				pnlOverView146.setDBptype113(bPTypeBean);
				//是否需要行政处罚集体讨论
				pnlOverView146.setIsneedbrainstorm(0L);
				//是否超出权限
				pnlOverView146.setIsexceedauthority(0L);
				//是否进行行政处罚听证
				pnlOverView146.setIsneedhow(0L);
				//是否需要组织复查
				pnlOverView146.setIsneedreview(0L);
				//是否申请人民法院强制执行
				pnlOverView146.setIscompulsoryexcecution(0L);
				//是否已申请人民法院强制执行
				pnlOverView146.setIsrecordcompulsoryexcecution(0L);
				//是否为分期付款
				pnlOverView146.setIsinstallment(0L);
				//是否案卷归档
				pnlOverView146.setIsarchived(0L);
				//是否有提起撤案
				pnlOverView146.setIshaverepealcase(0L);
				//是否以撤案结束
				pnlOverView146.setIsoverwithrc(0L);
				//是否能可以结案
				pnlOverView146.setIscanfinalapproval(0L);
				//是否已进行下一阶段
				pnlOverView146.setIsenternextbp(0L);
				//是否为末节点
				pnlOverView146.setIsendnode(1L);
				//报送时间
				pnlOverView146.setReportdate(new Date());
				//登记现场检查记录情况的用户ID
				pnlOverView146.setUUsrUser36ByUserid(pnlPorBean.getUUsrUser36ByUserid());
				//监管角度类型ID
				pnlOverView146.setDSuperviseviewtype83(pnlPorBean.getDSuperviseviewtype83());
				//数据类型ID
				DDatatype3 dataType146=new DDatatype3();
				dataType146.setDatatypeid(DATATYPE_146);
				pnlOverView146.setDDatatype3(dataType146);
				//数据状态ID
				DDatastatus4 datastatus=new DDatastatus4();
				datastatus.setDatastatusid(2L);
				pnlOverView146.setDDatastatus4(datastatus);
				//最近操作用户ID
				pnlOverView146.setUUsrUser36ByLatestoperateuserid(pnlPorBean.getUUsrUser36ByUserid());
				//是否标记删除
				pnlOverView146.setIsdeleted(0L);
				
				/**行政处罚流程记录表*/
				Set<EAqPnlOverviewbprecord561> aqPnlOverviewbprecord561s = pnlOverView146.getEAqPnlOverviewbprecord561s();
				//先删除旧的
				for (EAqPnlOverviewbprecord561 aqPnlOverviewbprecord561 : aqPnlOverviewbprecord561s) {
					aqPnlOverviewbprecord561.setIsdeleted(1L);
				}
				//在添加新的
				EAqPnlOverviewbprecord561 aqPnlOverviewbprecord561=new EAqPnlOverviewbprecord561();
				aqPnlOverviewbprecord561.setEAqPnlOverview146(pnlOverView146);
				aqPnlOverviewbprecord561.setDBptype113(pnlOverView146.getDBptype113());
				aqPnlOverviewbprecord561.setBpid(pnlPorBean.getPorid());
				aqPnlOverviewbprecord561.setReportdate(new Date());
				aqPnlOverviewbprecord561.setUUsrUser36(pnlOverView146.getUUsrUser36ByUserid());
				aqPnlOverviewbprecord561.setDDatastatus4(pnlOverView146.getDDatastatus4());
				aqPnlOverviewbprecord561.setDDatatype3(pnlOverView146.getDDatatype3());
				aqPnlOverviewbprecord561.setDSuperviseviewtype83(pnlOverView146.getDSuperviseviewtype83());
				aqPnlOverviewbprecord561.setIsdeleted(0L);
				aqPnlOverviewbprecord561s.add(aqPnlOverviewbprecord561);
				pnlOverView146.setEAqPnlOverviewbprecord561s(aqPnlOverviewbprecord561s);
				
				pnlOverView146s.add(pnlOverView146);
			}
		}
		pnlPorBean.setEAqPnlOverview146s(pnlOverView146s);
		pnlPorBean.setPunishunitnum(punishUnitNum);
		pnlPorBean.setParties(parties);
		pnlPorBean.setHaspunishedunitnum(0L);
		
		return pnlPorBean;
	}
}
